package  com.rboat.exam.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rboat.common.annotation.Log;
import com.rboat.common.enums.BusinessType;
import com.rboat.exam.domain.ExamTestUserAnswer;
import com.rboat.exam.service.IExamTestUserAnswerService;
import com.rboat.common.core.controller.BaseController;
import com.rboat.common.core.domain.AjaxResult;
import com.rboat.common.utils.poi.ExcelUtil;
import com.rboat.common.core.page.TableDataInfo;

/**
 * 考生答题Controller
 * 
 * @author rboat
 * @date 2019-09-02
 */
@Controller
@RequestMapping("/exam/answer")
public class ExamTestUserAnswerController extends BaseController
{
    private String prefix = "exam/answer";

    @Autowired
    private IExamTestUserAnswerService examTestUserAnswerService;

    @RequiresPermissions("exam:answer:view")
    @GetMapping()
    public String answer()
    {
        return prefix + "/answer";
    }

    /**
     * 查询考生答题列表
     */
    @RequiresPermissions("exam:answer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamTestUserAnswer examTestUserAnswer)
    {
        startPage();
        List<ExamTestUserAnswer> list = examTestUserAnswerService.selectExamTestUserAnswerList(examTestUserAnswer);
        return getDataTable(list);
    }

    /**
     * 导出考生答题列表
     */
    @RequiresPermissions("exam:answer:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamTestUserAnswer examTestUserAnswer)
    {
        List<ExamTestUserAnswer> list = examTestUserAnswerService.selectExamTestUserAnswerList(examTestUserAnswer);
        ExcelUtil<ExamTestUserAnswer> util = new ExcelUtil<ExamTestUserAnswer>(ExamTestUserAnswer.class);
        return util.exportExcel(list, "answer");
    }

    /**
     * 新增考生答题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考生答题
     */
    @RequiresPermissions("exam:answer:add")
    @Log(title = "考生答题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamTestUserAnswer examTestUserAnswer)
    {
        return toAjax(examTestUserAnswerService.insertExamTestUserAnswer(examTestUserAnswer));
    }

    /**
     * 修改考生答题
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ExamTestUserAnswer examTestUserAnswer = examTestUserAnswerService.selectExamTestUserAnswerById(id);
        mmap.put("examTestUserAnswer", examTestUserAnswer);
        return prefix + "/edit";
    }

    /**
     * 修改保存考生答题
     */
    @RequiresPermissions("exam:answer:edit")
    @Log(title = "考生答题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamTestUserAnswer examTestUserAnswer)
    {
        return toAjax(examTestUserAnswerService.updateExamTestUserAnswer(examTestUserAnswer));
    }

    /**
     * 删除考生答题
     */
    @RequiresPermissions("exam:answer:remove")
    @Log(title = "考生答题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examTestUserAnswerService.deleteExamTestUserAnswerByIds(ids));
    }
}
